package com.geektime.hello;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;

import java.util.List;

/**
 * @Author: DRevelation
 * @Date: 2021/2/2 9:45
 * Hutool工具类
 */
public class ExcelDemo {

    public static void main(String[] args) {
        readExcel();
    }

    private static void readExcel() {
        ExcelReader reader = ExcelUtil.getReader("D:\\data\\hutool_excel.xlsx");
        List<List<Object>> readAll = reader.read();
        System.out.println("readAll = " + readAll);
    }

    private static void writeExcel() {
        List<String> row1 = CollUtil.newArrayList("aa", "bb", "cc", "dd");
        List<String> row2 = CollUtil.newArrayList("aa1", "bb1", "cc1", "dd1");
        List<String> row3 = CollUtil.newArrayList("aa2", "bb2", "cc2", "dd2");
        List<String> row4 = CollUtil.newArrayList("aa3", "bb3", "cc3", "dd3");
        List<String> row5 = CollUtil.newArrayList("aa4", "bb4", "cc4", "dd4");

        List<List<String>> rows = CollUtil.newArrayList(row1, row2, row3, row4, row5);

        ExcelWriter writer = ExcelUtil.getWriter("D:\\data\\hutool_excel.xlsx");
        writer.passCurrentRow();
        writer.merge(row1.size() - 1, "测试标题");
        writer.write(rows, true);
        writer.close();
    }

}
